package com.ruoyi.performance.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.performance.domain.TTeacherAssess;
import com.ruoyi.performance.service.ITTeacherAssessService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 考核自评Controller
 * 
 * @author ruoyi
 * @date 2022-12-24
 */
@RestController
@RequestMapping("/selfAssessment")
public class TTeacherAssessController extends BaseController
{
    @Autowired
    private ITTeacherAssessService tTeacherAssessService;

    /**
     * 查询考核自评列表
     */
    @RequiresPermissions("performance:selfAssessment:list")
    @GetMapping("/list")
    public TableDataInfo list(TTeacherAssess tTeacherAssess)
    {
        startPage();
        List<TTeacherAssess> list = tTeacherAssessService.selectTTeacherAssessList(tTeacherAssess);
        return getDataTable(list);
    }

    /**
     * 导出考核自评列表
     */
    @RequiresPermissions("performance:selfAssessment:export")
    @Log(title = "考核自评", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTeacherAssess tTeacherAssess)
    {
        List<TTeacherAssess> list = tTeacherAssessService.selectTTeacherAssessList(tTeacherAssess);
        ExcelUtil<TTeacherAssess> util = new ExcelUtil<TTeacherAssess>(TTeacherAssess.class);
        util.exportExcel(response, list, "考核自评数据");
    }

    /**
     * 获取考核自评详细信息
     */
    @RequiresPermissions("performance:selfAssessment:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tTeacherAssessService.selectTTeacherAssessById(id));
    }

    /**
     * 新增考核自评
     */
    @RequiresPermissions("performance:selfAssessment:add")
    @Log(title = "考核自评", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTeacherAssess tTeacherAssess)
    {
        return toAjax(tTeacherAssessService.insertTTeacherAssess(tTeacherAssess));
    }

    /**
     * 修改考核自评
     */
    @RequiresPermissions("performance:selfAssessment:edit")
    @Log(title = "考核自评", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTeacherAssess tTeacherAssess)
    {
        return toAjax(tTeacherAssessService.updateTTeacherAssess(tTeacherAssess));
    }

    /**
     * 删除考核自评
     */
    @RequiresPermissions("performance:selfAssessment:remove")
    @Log(title = "考核自评", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tTeacherAssessService.deleteTTeacherAssessByIds(ids));
    }

    /**
     * 完成自评
     * @param id
     * @return
     * @throws Exception
     */
    @RequiresPermissions("performance:selfAssessment:change")
    @GetMapping(value = "/changeState/{id}")
    public AjaxResult changeState(@PathVariable("id") Long id) throws Exception {
        return success(tTeacherAssessService.changeState(id));
    }

    /**
     * 完成审核
     * @param id
     * @return
     */
    @RequiresPermissions("performance:selfAssessment:auditPass")
    @GetMapping(value = "/auditPass/{id}")
    public AjaxResult auditPass(@PathVariable("id") Long id) {
        return success(tTeacherAssessService.auditPass(id));
    }

    /**
     * 生成本月绩效
     * @return
     */
    @RequiresPermissions("performance:selfAssessment:generatePerformance")
    @GetMapping(value = "/generatePerformance")
    public AjaxResult generatePerformance()
    {
        return success(tTeacherAssessService.generatePerformance());
    }
}
